package com.hzhc.controller.yworder;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.YwOrderCntrAuditService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.YwOrderCntrAuditVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 箱修改申请 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-08-30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cntrAudit")
public class YwOrderCntrAuditController extends BaseController {
    private final YwOrderCntrAuditService ywOrderCntrAuditService;

    /**
     * 查询箱申请
     */
    @RequestMapping("/getCntrAuditList")
    public ResultUtil<List<YwOrderCntrAuditVo>> getCntrAuditList(@RequestBody YwOrderCntrAuditVo vo) {
        Page<YwOrderCntrAuditVo> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
        List<YwOrderCntrAuditVo> vos = ywOrderCntrAuditService.getCntrAuditList(page, vo);
        return ResultUtil.build(vos,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 新增箱申请
     */
    @PostMapping("/addCntrAuditRet")
    public ResultUtil<T> addCntrAuditRet(@RequestBody YwOrderCntrAuditVo vo, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setCreateTime(LocalDateTime.now());
        return ywOrderCntrAuditService.addCntrAuditRet(vo);
    }

    /**
     * 审核
     */
    @PostMapping("/updateCntrAuditRet")
    public ResultUtil<T> updateCntrAuditRet(@RequestBody YwOrderCntrAuditVo vo, HttpServletRequest request) {
        UserDto user = TokenUtil.getUser(request);
        vo.setUpdateUserId(user.getId());
        vo.setUpdateTime(LocalDateTime.now());
        return ywOrderCntrAuditService.updateCntrAuditRet(vo);
    }
}
